package UI.MultiPlayer;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import UI.MultiPlayer.VideoPlayer;

/**
 * @author 杨明政
 * @version  2021.0520
 * @since 1.8
 */

/**
 * 图片预览类.
 * For example:
 * <pre>
 * PlayWindow u=new PlayWindow();
 * </pre>
 * @author 杨明政
 * @see javax.swing.JComponent
 * @see javax.swing.JPanel
 */

public class PlayWindow extends JFrame implements ActionListener{
    private JPanel contentPane;
    //创建播放器界面组件
    EmbeddedMediaPlayerComponent playerComponent =
            new EmbeddedMediaPlayerComponent();
    private final JPanel panel = new JPanel();
    private JButton EXIT;
    
    public PlayWindow() {
        setTitle("View Window");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(600, 200, 700, 555);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);
        JPanel videoPanel = new JPanel();
        EXIT =new JButton("EXIT");
        EXIT.addActionListener(this);
        EXIT.setFont(new Font("Serif", Font.PLAIN, 20));
        contentPane.add(videoPanel, BorderLayout.CENTER);
        videoPanel.setLayout(new BorderLayout(0, 0));
        //将播放器界面添加到videopanel中，用来播放视频，并设置布局为居中
        playerComponent = new EmbeddedMediaPlayerComponent();
        videoPanel.add(playerComponent, BorderLayout.CENTER);
        videoPanel.add(panel, BorderLayout.SOUTH);
        panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        panel.add(EXIT);
        
    }
    /**
     * 返回视频播放器
     * @return    视频播放器.
     */
    public EmbeddedMediaPlayer getMediaPlayer() {
        return playerComponent.getMediaPlayer();
    }

    /**
     * 动作处理
     * @param e 动作事件
     */
    @Override
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==EXIT)
        {
            VideoPlayer.frame.getMediaPlayer().release();
            dispose();
        }
    }
}
